import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:glorysoft_mobile_plugin/tool/extensions/extension.dart';

import 'progress_dialog_controller.dart';

class ProgressDialogWidget extends StatelessWidget {
  final controller = Get.put(ProgressDialogController());
  String title;

  ProgressDialogWidget({required this.title, required String url}) {
    controller.url = url;
    controller.downloadApk();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProgressDialogController>(builder: (controller) {
      return WillPopScope(
        onWillPop: () async => false,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            GFAlert(
              title: title,
              titleTextStyle: const TextStyle(
                color: Colors.black87,
                fontSize: 17,
                fontWeight: FontWeight.w500,
                decoration: TextDecoration.none,
              ),
              contentChild: Column(
                children: [
                  SizedBox(
                    height: 10,
                    child: ClipRRect(
                      borderRadius: BorderRadius.all(Radius.circular(10.0)),
                      child: LinearProgressIndicator(
                        value: controller.value,
                        valueColor: AlwaysStoppedAnimation<Color>(
                            ("#0088CC").toColor()),
                        backgroundColor: Colors.grey[300],
                      ),
                    ),
                  ),
                  Text((controller.value*100).round().toString()+"%",style: TextStyle(
                    color: Colors.black87,
                    fontSize: 17,
                    fontWeight: FontWeight.w500,
                    decoration: TextDecoration.none,
                  )).marginOnly(top: 4)
                ],
              ),
              type: GFAlertType.rounded,
            ),
          ],
        ),
      );
    });
  }
}
